package com.thinkgem.jeesite.frame.pm.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.SqlCondition;
import com.google.common.collect.Lists;
import com.thinkgem.jeesite.frame.pm.PmConstants;
import com.thinkgem.jeesite.kpoint.core.base.KpointBaseEntity;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Length;

import java.util.List;

;

/**
 * 数据字典Entity
 *
 * @author kongxiangsheng
 * @version 2018-09-02
 */
@Data
public class PmDataTree extends KpointBaseEntity {
    public static final String COL_TREE_CODE = "`tree_code`";
    public static final String COL_TREE_NAME = "`tree_name`";
    public static final String COL_ALLOW_DELETE = "`allow_delete`";

    private static final long serialVersionUID = 1L;
    /**
     * 编号
     */
    @TableField(condition = SqlCondition.LIKE)
    @Length(min = 1, max = 30, message = "编号长度必须介于 1 和 30 之间")
    private String treeCode;
    /**
     * 名称
     */
    @TableField(condition = SqlCondition.LIKE)
    @Length(min = 1, max = 30, message = "名称长度必须介于 1 和 30 之间")
    private String treeName;
    /**
     * 是否允许删除
     */
    @Length(min = 0, max = 1, message = "是否允许删除长度必须介于 0 和 1 之间")
    private String allowDelete;

    /**
     * 最多层级数
     */
    private Integer maxLevel;
    /**
     * 拓展字段1说明
     */
    private String extAttr1Desc;
    /**
     * 拓展字段2说明
     */
    private String extAttr2Desc;
    /**
     * 拓展字段3说明
     */
    private String extAttr3Desc;
    /**
     * 拓展字段4说明
     */
    private String extAttr4Desc;
    /**
     * 拓展字段5说明
     */
    private String extAttr5Desc;
    /**
     * 拓展字段6说明
     */
    private String extAttr6Desc;
    /**
     * 拓展字段7说明
     */
    private String extAttr7Desc;
    /**
     * 子表列表
     */
    @TableField(exist = false)
    private List<PmDataTreeItem> pmDataTreeItemList = Lists.newArrayList();

    public String getExtAttr1Name() {
        return getExtAttrProperty(extAttr1Desc, PmConstants.ExtAttrCode.NAME);
    }

    public String getExtAttr1Edit() {
        return getExtAttrProperty(extAttr1Desc, PmConstants.ExtAttrCode.EDIT);
    }

    public String getExtAttr1List() {
        return getExtAttrProperty(extAttr1Desc, PmConstants.ExtAttrCode.LIST);
    }

    public String getExtAttr1Need() {
        return getExtAttrProperty(extAttr1Desc, PmConstants.ExtAttrCode.NEED);
    }

    public String getExtAttr2Name() {
        return getExtAttrProperty(extAttr2Desc, PmConstants.ExtAttrCode.NAME);
    }

    public String getExtAttr2Edit() {
        return getExtAttrProperty(extAttr2Desc, PmConstants.ExtAttrCode.EDIT);
    }

    public String getExtAttr2List() {
        return getExtAttrProperty(extAttr2Desc, PmConstants.ExtAttrCode.LIST);
    }

    public String getExtAttr2Need() {
        return getExtAttrProperty(extAttr2Desc, PmConstants.ExtAttrCode.NEED);
    }

    public String getExtAttr3Name() {
        return getExtAttrProperty(extAttr3Desc, PmConstants.ExtAttrCode.NAME);
    }

    public String getExtAttr3Edit() {
        return getExtAttrProperty(extAttr3Desc, PmConstants.ExtAttrCode.EDIT);
    }

    public String getExtAttr3List() {
        return getExtAttrProperty(extAttr3Desc, PmConstants.ExtAttrCode.LIST);
    }

    public String getExtAttr3Need() {
        return getExtAttrProperty(extAttr3Desc, PmConstants.ExtAttrCode.NEED);
    }

    public String getExtAttr4Name() {
        return getExtAttrProperty(extAttr4Desc, PmConstants.ExtAttrCode.NAME);
    }

    public String getExtAttr4Edit() {
        return getExtAttrProperty(extAttr4Desc, PmConstants.ExtAttrCode.EDIT);
    }

    public String getExtAttr1Type() {
        return getExtAttrProperty(extAttr1Desc, PmConstants.ExtAttrCode.TYPE);
    }

    public String getExtAttr2Type() {
        return getExtAttrProperty(extAttr2Desc, PmConstants.ExtAttrCode.TYPE);
    }

    public String getExtAttr3Type() {
        return getExtAttrProperty(extAttr3Desc, PmConstants.ExtAttrCode.TYPE);
    }

    public String getExtAttr4Type() {
        return getExtAttrProperty(extAttr4Desc, PmConstants.ExtAttrCode.TYPE);
    }

    public String getExtAttr5Type() {
        return getExtAttrProperty(extAttr5Desc, PmConstants.ExtAttrCode.TYPE);
    }

    public String getExtAttr6Type() {
        return getExtAttrProperty(extAttr6Desc, PmConstants.ExtAttrCode.TYPE);
    }

    public String getExtAttr7Type() {
        return getExtAttrProperty(extAttr7Desc, PmConstants.ExtAttrCode.TYPE);
    }

    public String getExtAttr4List() {
        return getExtAttrProperty(extAttr4Desc, PmConstants.ExtAttrCode.LIST);
    }

    public String getExtAttr4Need() {
        return getExtAttrProperty(extAttr4Desc, PmConstants.ExtAttrCode.NEED);
    }

    public String getExtAttr5Name() {
        return getExtAttrProperty(extAttr5Desc, PmConstants.ExtAttrCode.NAME);
    }

    public String getExtAttr5Edit() {
        return getExtAttrProperty(extAttr5Desc, PmConstants.ExtAttrCode.EDIT);
    }

    public String getExtAttr5List() {
        return getExtAttrProperty(extAttr5Desc, PmConstants.ExtAttrCode.LIST);
    }

    public String getExtAttr5Need() {
        return getExtAttrProperty(extAttr5Desc, PmConstants.ExtAttrCode.NEED);
    }

    public String getExtAttr6Name() {
        return getExtAttrProperty(extAttr6Desc, PmConstants.ExtAttrCode.NAME);
    }

    public String getExtAttr6Edit() {
        return getExtAttrProperty(extAttr6Desc, PmConstants.ExtAttrCode.EDIT);
    }

    public String getExtAttr6List() {
        return getExtAttrProperty(extAttr6Desc, PmConstants.ExtAttrCode.LIST);
    }

    public String getExtAttr6Need() {
        return getExtAttrProperty(extAttr6Desc, PmConstants.ExtAttrCode.NEED);
    }

    public String getExtAttr7Name() {
        return getExtAttrProperty(extAttr7Desc, PmConstants.ExtAttrCode.NAME);
    }

    public String getExtAttr7Edit() {
        return getExtAttrProperty(extAttr7Desc, PmConstants.ExtAttrCode.EDIT);
    }

    public String getExtAttr7List() {
        return getExtAttrProperty(extAttr7Desc, PmConstants.ExtAttrCode.LIST);
    }

    public String getExtAttr7Need() {
        return getExtAttrProperty(extAttr7Desc, PmConstants.ExtAttrCode.NEED);
    }

    /**
     * 获取拓展字段的属性
     *
     * @param extAttr
     * @param propertyCode
     * @return
     */
    private String getExtAttrProperty(String extAttr, String propertyCode) {
        if (StringUtils.isBlank(extAttr) || StringUtils.isBlank(propertyCode)) {
            return "";
        }
        String propertyValue = "";
        String[] properties = extAttr.split("\\|");
        for (String property : properties) {
            if (property.startsWith(propertyCode + ":")) {
                propertyValue = property.substring(propertyCode.length() + 1);
                break;
            }
        }
        return propertyValue;
    }
}